import {DataNode} from "@/pages/script";
import {TreeDataNode} from "antd";

export interface RoleProp {
    id: number;
    name: string;
    code: string;
    brief: string;
    createTime: string;
    permIds?: number[];
}

export interface RoleQueryProp {
    page: number;
    size: number;
    name?: string;
}

// RoleCreateFormProp 角色创建表单
export interface RoleCreateFormProp {
    name: string
    code: string
    desc: string
}

// RoleCreateModelProp 角色创建模态框值
export interface RoleCreateModelProp {
    visible: boolean;
    onCancel: (isLoad: boolean) => void;
}

// 用户管理分页
export interface UserListProp {
    id: number;
    name: string;
    sex: number;
    phone: string; // 手机号
    email: string; // 邮箱
    status: number; // 用户状态
    avatar: string; // 头像
    desc: string;   // 描述
    userRole: UserRoleProp[]; // 用户角色
}

export interface UserRoleProp {
    roleId: number;
    roleName: string;
}

export interface UserQueryProp {
    page: number;
    size: number;
    name?: string;
}

// UserInfoDrawerProp 用户详情抽屉参数
export interface UserInfoDrawerProp {
    visible: boolean;
    userId?: number;
    close: () => void;
}

// UserAuthDrawerProp 用户授权抽屉参数
export interface UserAuthDrawerProp {
    visible: boolean;
    userId?: number;
    close: () => void;
}

// UserEditDrawerProp 账号编辑抽屉参数
export interface UserEditDrawerProp {
    visible: boolean;
    userId?: number;
    close: (isLoad: boolean) => void;
}

// UserDrawerProp 用户抽屉参数
export interface UserDrawerProp {
    infoVisible: boolean;
    authVisible: boolean;
    editVisible: boolean;
    userId?: number;
    types?: DrawerType;
}

export const defaultUserDrawerProp: UserDrawerProp = {
    infoVisible: false,
    authVisible: false,
    editVisible: false,
    userId: undefined,
    types: undefined,
}

export const changeUserDrawer = (types: DrawerType, userId: number | undefined, show: boolean): UserDrawerProp => {
    switch (types) {
        case "auth":
            return {authVisible: show, infoVisible: false, editVisible: false, userId: userId, types: types};
        case "info":
            return {authVisible: false, infoVisible: show, editVisible: false, userId: userId, types: types};
        case "edit":
            return {authVisible: false, infoVisible: false, editVisible: show, userId: userId, types: types};
        default:
            return defaultUserDrawerProp;
    }
}

// 抽屉类型
export type DrawerType = 'info' | 'auth' | 'edit';

export interface RoleKeyValueProp {
    value: number;
    label: string;
}

// UserEditFormProp 用户编辑表单属性
export interface UserEditFormProp {
    id: number; // 用户ID
    name: string; // 用户名称
    phone: string; // 手机号
    email: string; // 邮箱
    sex: number; // 性别
    desc?: string; // 描述
    userStatus: number; // 用户状态
    roleId?: number[]; // 授权角色
    roles: RoleKeyValueProp[]; // 全部角色
}

// PermissionTreeProp 权限树
export interface PermissionTreeProp extends TreeDataNode {
    key: number;
    title: string;
    level?: number;
    treeType?: number;
    isLeaf?: boolean;
    sortNo?: number;
    children?: PermissionTreeProp[];
}

// PermissionListProp 资源表格属性
export interface PermissionListProp {
    id: number; // 主键
    title: string; // 资源名称
    code: string; // 编码
    icon: string; // 图标
    path?: string; // 路由
    permType: number; // 资源类型
    parentId: number; // 上级ID
    level: number; // 层级
    order: number; // 排序
    createTime: string; // 创建时间
    createId: number; // 创建人ID
    createName: string; // 创建人名称
}

// CreatePermissionProp 创建资源
export interface CreatePermissionProp {
    types: number;
    parentId: number;
    visible: boolean;
    close: (isLoad: boolean, data?: PermissionListProp) => void;
}

// CreatePermissionFormProp 创建资源表单属性
export interface CreatePermissionFormProp {
    name: string; // 资源名称
    code: string; // 资源编码
    parentId: number; // 上级资源ID
    permType: number; // 资源类型
    icon?: string; // 图标
    path?: string; // 路径
    orderNo: number; // 资源权重
    brief?: string; // 备注
    userId?: number; // 创建人ID
}


// UpdatePermissionProp 修改资源
export interface UpdatePermissionProp {
    id: number;
    types?: number;
    visible: boolean;
    close: (isLoad: boolean, data?: PermissionListProp) => void;
}

// InfoPermissionProp 资源详情
export interface InfoPermissionProp {
    id: number;
    visible: boolean;
    close: () => void;
}

// UpdatePermissionFormProp 修改资源表单属性
export interface UpdatePermissionFormProp extends CreatePermissionFormProp {
    id: number;
}

// DrawerProp 抽屉参数
export interface DrawerProp {
    types?: number;
    currId?: number;
    parentId?: number;
    createVisible: boolean;
    updateVisible: boolean;
    infoVisible: boolean;
}

// PermissionInfoProp 资源详情
export interface PermissionInfoProp {
    id:         number;
    name:       string;
    code:       string;
    createId:   number;
    createName: string;
    createTime: string;
    icon?:       string;
    level:      number;
    order:      number;
    parentId:   number;
    parentName?: string;
    path?:       string;
    permType:   number;
    updateId?:   number;
    updateName?: string;
    updateTime?: string;
    brief?: string;
}

// DrawerUpdateRoleProp 角色更新
export interface DrawerUpdateRoleProp {
    visible: boolean;
    roleData?: RoleProp;
    close: (isLoad: boolean, data?: RoleProp) => void;
}

export interface DrawerRoleProp {
    data?: RoleProp;
    editVisible: boolean;
    addVisible: boolean;
}

// UpdateRoleFormProp 更新角色表单属性
export interface UpdateRoleFormProp {
    id: number;
    name: string;
    code: string;
    brief: string;
    permId: number[];
}

// UserDetailProp 用户详情
export interface UserDetailProp {
    id: number;
    name: string;
    phone: string;
    email: string;
    sex: number;
    desc: string;
    userStatus: number;
    roleIds: number[];
    permIds: number[];
}

